﻿using System;

using Norm;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.DataAccess;

namespace Fuse8.DomainFramework.MongoDbWrapper
{
    public class HttpContextMongoDbUnitOfWorkFactory<T> : HttpContextUnitOfWorkFactory<T>
        where T : class, IEntityObject, new()
    {
        /// <summary>
        /// 
        /// </summary>
        protected override string FactoryKeyFormat
        {
            get
            {
                return "HttpCurrentMongoDbUnitOfWork_{0}";
            }
        }

        #region HttpContextUnitOfWorkFactory overrides

        public override IUnitOfWork<T> Create(bool withTransaction)
        {
            if (withTransaction)
            {
                throw new NotSupportedException();
            }

            return new MongoDbUnitOfWork<T>
            {
                CurrentDb = Mongo.Create(MongoDbConnection.GetInstance().ConnectionString)
            };
        }

        public override IUnitOfWork<T> CreateFrom<TMain>(IUnitOfWork<TMain> unitOfWork)
        {
            throw new NotSupportedException();
        }

        public override void CommitTransaction()
        {
            throw new NotSupportedException();
        }

        public override void RollbackTransaction()
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
